<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>电脑商城</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="../bootstrap3/js/holder.js"></script>
		<link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
		<script src="../bootstrap3/js/bootstrap.js"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="../css/top.css" />
		<link rel="stylesheet" type="text/css" href="../css/index.css" />
		<link rel="stylesheet" type="text/css" href="../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../css/reg.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
	</head>
	<style>
		#regtitle{
			margin-left: 40%;
			font-size: 20px;
			font-weight: bold;
		}
		#username_notice{
			margin-left: 15%;
			font-size: 10px;
			color: rgba(255,255,255,0.85);
		}
		#password_notice{
			margin-left: 15%;
			font-size: 10px;
			color: rgba(255,255,255,0.85);
		}
	</style>
	<body>
		<!--头部-->
		<header class="header">
			<img src="../images/index/stumalllogo.png" alt="" />
			<span class="pull-right"><small>欢迎访问</small><b>电脑商城</b></span>
		</header>
		<!--主体-->
		<div class="container mycontent text-left">
			<!--透明层 -->
			<div class="regDiv">
				<p id="regtitle">新用户注册</p>
				<!--表单开始-->
				<form id="form-reg" class="form-horizontal" role="form">
					<!--用户名-->
					<div class="form-group">
						<p id="username_notice">*请输入长度为5-8位的用户名且不能为空</p>
						<label class="col-md-3 control-label">名字：</label>
						<div class="col-md-8">
							<input id="username_value" onblur="userMethod()" name="username" type="text" class="form-control" placeholder="请输入用户名">
						</div>
					</div>
					<!--密码-->
					<div class="form-group">
						<p id="password_notice">*密码不能为空或两次密码输入不一致</p>
						<label class="col-md-3 control-label"> 密码：</label>
						<div class="col-md-8">
							<input id="pwd1" onblur="pwdMethod()" name="password" type="text" class="form-control" placeholder="请输入密码">
						</div>
					</div>
					<!--确认密码-->
					<div class="form-group">
						<label class="col-md-3 control-label"> 确认密码：</label>
						<div class="col-md-8">
							<input id="pwd2" onblur="pwdMethod()" type="text" class="form-control" placeholder="请再次输入密码">
						</div>
					</div>
					<!--提交按钮-->
					<div class="form-group">
						<label class="col-md-3 control-label"></label>
						<div class="col-md-8">
							<input id="btn-reg" class="btn btn-primary" type="button" value="立即注册" />
							<span class="pull-right"><small>已经有账号？</small><a href="login.html">登录</a></span>
						</div>
					</div>
				</form>
			</div>
		</div>
		<!--页脚开始-->
		<footer class="footer">
			<!-- 品质保障，私人定制等-->
			<div class="text-center rights container">
				<div class="col-md-offset-2 col-md-2">
					<span class="fa fa-thumbs-o-up"></span>
					<p>品质保障</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-address-card-o"></span>
					<p>私人订制</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-graduation-cap"></span>
					<p>学生优惠</p>
				</div>
				<div class="col-md-2">
					<span class="fa fa-bitcoin"></span>
					<p>专属特权</p>
				</div>
			</div>
			<!--联系我们、下载客户端等-->
			<div class="container beforeBottom">
				<div class="col-md-offset-1 col-md-3">
					<div><img src="../images/index/stumalllogo.png" alt="" class="footLogo" /></div>
					<div><img src="../images/index/footerFont.png" alt="" /></div>
				</div>
				<div class="col-md-4 callus text-center">
					<div class="col-md-4">
						<ul>
							<li><a href="#">新手指南</a></li>
							<li><a href="#">服务保障</a></li>
							<li><a href="#">常见问题</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#">商家帮助</a></li>
							<li><a href="#">商家入驻</a></li>
							<li><a href="#">商家后台</a></li>
						</ul>
					</div>
					<div class="col-md-4">
						<ul>
							<li><a href="#">关于我们</a></li>
							<li><a href="#">联系我们</a></li>
							<li>
								<span class="fa fa-wechat"></span>
								<span class="fa fa-weibo"></span>
							</li>
						</ul>
					</div>
				</div>
				<div class="col-md-4">
					<div class="col-md-5">
						<p>电脑商城客户端</p>
						<img src="../images/index/ios.png" class="lf">
						<img src="../images/index/android.png" alt="" class="lf" />
					</div>
				</div>
			</div>
			<!-- 页面底部-备案号 #footer -->
			<div class="col-md-12 text-center bottom">
				Copyright © 2022 dnsc.cn All Rights Reserved javaweb小组
			</div>
		</footer>
		<!--页脚结束-->
		<!-- 编写javascript脚本 -->
		<script type="text/javascript">
			//失焦方法
			function userMethod()
			{
				var user = document.getElementById('username_value').value;
				// console.log(user)
				if(user.length<5 || user.length>8 ||user == null){
					document.getElementById('username_notice').style.color="red";
				}else{
					document.getElementById('username_notice').style.color='green';
				}

			}

			function pwdMethod()
			{
				var pwd1 = document.getElementById('pwd1').value;
				var pwd2 = document.getElementById('pwd2').value;
				console.log(pwd1,pwd2)
				if(pwd1.length ==0 || pwd2.length == 0 || pwd1!==pwd2 ){
					document.getElementById('password_notice').style.color="red";
				}else{
					document.getElementById('password_notice').style.color='green';
				}

			}
			// 1、监听注册按钮是否被点击
			$("#btn-reg").click(function () {


				// 2、发送ajax()的异步请求来完成用户的注册功能
				$.ajax({
					url: "/users/reg",
					type: "POST",
					// $("#form-reg").serialize()相当于：username=tom&password=1232
					data: $("#form-reg").serialize(),
					dataType: "JSON",
					success: function (json) {
						if (json.state == 200){

							alert("注册成功");
						}else {
							alert("注册失败,原因：" + json.message);

						}

					},
					error: function (xhr){
						alert("注册时产生未知错误：" + xhr.status);

					}
				})
			});

		</script>
	</body>
</html>